#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=4e4+10;
int n,head[MAXN],cnt,_x[]={-1,-2,1,2,-1,-2,1,2},_y[]={-2,-1,-2,-1,2,1,2,1},match[MAXN],ans,tot;
char a[210][210];
bool vis[MAXN];
struct edge
{
	int v,next;
}e[MAXN*20];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
inline int P(int x,int y)
{
	return (x-1)*n+y;
}
bool Hungary(int u)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(!vis[v])
		{
			vis[v]=true;
			if(!match[v]||Hungary(match[v]))
			{
				match[v]=u;
				return true;
			}
		}
	}
	return false;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();
	for(int i=1;i<=n;++i)
		scanf("%s",a[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
		{
			if(a[i][j]=='1')
			{
				++tot;
				continue;
			}
			for(int k=0;k<8;++k)
			{
				int x=i+_x[k],y=j+_y[k];
				if(x<1||y<1||x>n||y>n||a[x][y]=='1')continue;
				addedge(P(i,j),P(x,y));
				addedge(P(x,y),P(i,j));
			}
		}
	for(int i=1;i<=n*n;++i)
	{
		memset(vis,0,sizeof(vis));
		if(Hungary(i))++ans;
	}
	printf("%d\n",n*n-tot-ans/2);
	return 0;
}
